<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <a id="box" href="https://www.baidu.com">This is a DIV</a>
    <script>
        var boxObj = document.getElementById('box');
        function warning(e){
            e.preventDefault();
            console.log('Warning!');
            return false;
        }
        var fun = function(e){
            alert('aaa')
            e.preventDefault();  //可以阻止a的默认行为
            console.log('Hello world');
            // warning(e);  //调用warning时无法阻止a的默认跳转行为
            // return false;  //也无法阻止a的默认跳转行为
        };
        boxObj.addEventListener('click',fun,false);
        var e = new Event('click');
         console.log(e.cancelable=true);
        var c = boxObj.dispatchEvent(e); //当监听函数调用event.preventDefault()时，c始终未true
    </script>
</body>
</html>